﻿package view.effect
{
    import __AS3__.vec.*;
    import com.core.*;
    import com.greensock.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import consts.*;
    import flash.display.*;
    import flash.geom.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.handlers.*;
    import plugin.NewSkill.consts.*;

    public class ItemEffects extends Object
    {
        private var _queue:Array;
        private var _items:Vector.<Bitmap>;
        private var _container:Sprite;
        private var _intvalid:uint = 0;

        public function ItemEffects(param1:Object)
        {
            this._queue = new Array();
            this._items = new Vector.<Bitmap>;
            this._container = Sprite(param1);
            return;
        }// end function

        public function add(param1:Object) : void
        {
            var _loc_2:Object = null;
            if (param1 is Array)
            {
                for each (_loc_2 in param1)
                {
                    
                    this._queue.push(_loc_2);
                }
            }
            else
            {
                this._queue.push(param1);
            }
            this.startMove();
            return;
        }// end function

        public function startMove() : void
        {
            if (this._intvalid == 0)
            {
                this._intvalid = setInterval(this.next, 150);
            }
            return;
        }// end function

        private function next() : void
        {
            var _loc_1:Object = null;
            if (this._queue.length > 0)
            {
                _loc_1 = this._queue.shift();
                App.loader.loadBMD(Config.getUrl("assets/images/icon/tools/" + _loc_1.icon + ".png"), new Handler(this.loadedHandler, [_loc_1]));
                if (this._queue.length == 0)
                {
                    this.clearRender();
                }
            }
            return;
        }// end function

        private function loadedHandler(param1:Object, param2:BitmapData) : void
        {
            var _loc_3:Point = null;
            var _loc_4:Bitmap = null;
            var _loc_5:Point = null;
            var _loc_6:int = 0;
            var _loc_7:Array = null;
            var _loc_8:Object = null;
            if (param2)
            {
                _loc_3 = UIGlobel.pointsDic["bag"];
                if (_loc_3)
                {
                    _loc_4 = new Bitmap(param2);
                    _loc_4.scaleX = 0.8;
                    _loc_4.scaleY = 0.8;
                    this._items.push(_loc_4);
                    this._container.addChild(_loc_4);
                    if (param1.hasOwnProperty("x"))
                    {
                        _loc_4.x = param1.x;
                        _loc_4.y = param1.y;
                    }
                    else if (param1.middle)
                    {
                        _loc_4.x = this._container.stage.stageWidth / 2 - 30;
                        _loc_4.y = this._container.stage.stageHeight / 2 - 30;
                    }
                    else if (param1.qianghua)
                    {
                        _loc_4.x = ModelProxy.getValue("data", "hechengpoint").x;
                        _loc_4.y = ModelProxy.getValue("data", "hechengpoint").y;
                    }
                    else if (int(param1.itemid) > 0)
                    {
                        _loc_4.x = this._container.stage.mouseX;
                        _loc_4.y = this._container.stage.mouseY;
                        _loc_5 = UIGlobel.pointsDic["setskill"];
                        _loc_6 = _loc_5.x + 42 * 8 + 14;
                        _loc_7 = [param1.itemid, 2, 9];
                        _loc_8 = {pos:8, type:2, id:param1.itemid};
                        if (int(param1.itemid) == Constant.SUIJISHI2)
                        {
                            _loc_6 = _loc_5.x + 42 * 9 + 14;
                            _loc_7 = [param1.itemid, 2, 10];
                        }
                        TweenLite.to(_loc_4, 3, {x:_loc_6 + 6, y:_loc_5.y, onComplete:this.tweenEnd, onCompleteParams:[_loc_4, true, _loc_7]});
                        return;
                    }
                    else
                    {
                        _loc_4.x = this._container.stage.mouseX;
                        _loc_4.y = this._container.stage.mouseY;
                    }
                    TweenLite.to(_loc_4, 3, {x:_loc_3.x + 6, y:_loc_3.y, onComplete:this.tweenEnd, onCompleteParams:[_loc_4, false, null]});
                }
            }
            return;
        }// end function

        private function tweenEnd(param1:Bitmap, param2:Boolean, param3:Array) : void
        {
            if (param2)
            {
                ModelProxy.change("fastlist", "setskill", param3);
                PluginManager.instance.sendToServer("skill", CMDSkill.SetSkill, {id:param3[0], type:param3[1], topos:param3[2]});
            }
            var _loc_4:* = this._items.indexOf(param1);
            if (this._items.indexOf(param1) > -1)
            {
                this._items.splice(_loc_4, 1);
            }
            if (param1.parent)
            {
                param1.parent.removeChild(param1);
            }
            return;
        }// end function

        private function clearRender() : void
        {
            if (this._intvalid > 0)
            {
                clearInterval(this._intvalid);
                this._intvalid = 0;
            }
            return;
        }// end function

        public function clear() : void
        {
            var _loc_1:Bitmap = null;
            this._queue.length = 0;
            for each (_loc_1 in this._items)
            {
                
                if (_loc_1.parent)
                {
                    _loc_1.parent.removeChild(_loc_1);
                }
            }
            this._items.length = 0;
            this.clearRender();
            return;
        }// end function

    }
}
